Nil Keyword

Used to determine if an object is nil (no value).

expression=Nil


Notes

Nil means no value. When an object is first instantiated, it is automatically initialized to Nil. Some functions will return a Nil value under certain circumstances. GetOpenFolderItem will return Nil if the user clicks the Cancel button when GetOpenFolderItem presents the standard open file dialog box.

If you try to access an object that has a Nil value, a NilObjectException error will be generated. If you don't handle the exception, execution will stop. If you are testing the application in the IDE, you can select Project . Break on Exceptions to halt execution whenever a runtime exception error occurs and open the Debugger.

If the code executes in a built application, the user will see a generic error message before the application quits.

To prevent this, you should always test for Nil values, either with an If statement or by including a Try or Exception block at the end of the method.


Example

This example uses the Nil keyword to determine if the user clicked the Cancel button in the standard open file dialog box presented by the GetOpenFolderItem function.

Dim f as FolderItem
f= GetOpenFolderItem("image/x-pict") //defined as a FileType
If f <> Nil Then
 //the user clicked OK so continue here
End If

This example uses an Exception block to handle NilObjectExceptions.

Dim f as FolderItem
Try
 f= GetOpenFolderItem("image/x-pict")

Catch err as NilObjectException
  MsgBox err.message

See Also

RuntimeException class; Exception, Try blocks; NilObjectException error.